package com.ksm.client.document.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Singleton;
import com.ksm.client.document.presenter.DocumentPreviewPresenter.IDocumentPreviewView;
import com.ksm.client.document.presenter.IDocumentPreviewPresenter;
import com.sencha.gxt.widget.core.client.Component;

@Singleton
public class DocumentPreviewView extends ResizeComposite implements IsWidget, IDocumentPreviewView {

	interface MyUiBinder extends UiBinder<Component, DocumentPreviewView> {
	}

	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
	private static final String FILE_BASE_LOCATION = "file//store//";
	private final Widget uiWidget;
	private IDocumentPreviewPresenter presenter;
	@UiField
	public Image imageWidget;

	public DocumentPreviewView() {
		uiWidget = uiBinder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return uiWidget;
	}

	@Override
	public void updateImage(String url) {
		if (url != null) {
			imageWidget.setUrl(GWT.getModuleBaseURL() + "download?filename=" + url);
		} else {
			imageWidget.setUrl("");
		}
	}

	@Override
	public IDocumentPreviewPresenter getPresenter() {
		return presenter;
	}

	@Override
	public void setPresenter(IDocumentPreviewPresenter presenter) {
		this.presenter = presenter;
	}

}